class MyStack {
public:
    queue<int>a;
    queue<int>b;
    int cnt = 0;
    void push(int x) {
        a.push(x);
        cnt++;
    }

    int pop() {
        for (int i = 1; i < cnt; i++) {
            b.push(a.front());
            a.pop();
        }
        int answer = a.front();
        a.pop();
        cnt--;
        for (int i = 1; i <= cnt; i++) {
            a.push(b.front());
            b.pop();
        }
        return answer;
    }

    int top() {
        for (int i = 1; i < cnt; i++) {
            b.push(a.front());
            a.pop();
        }
        int answer = a.front();
        b.push(a.front());
        a.pop();
        for (int i = 1; i <= cnt; i++) {
            a.push(b.front());
            b.pop();
        }
        return answer;
    }

    bool empty() {
        if (a.empty()) { return true; }
        else { return false; }
    }
};